package com.iol.stpso.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class Utils {
	
	public static String zeroFill(long number, int size) {
		int digtis = size;
		boolean negative = false;// 负数
		
		if (size<0){
			return null;
		}
		if (size==0){
			return "";
		}
		if (number>0){
			if (size <= 1) {
				return null;
			}
			negative = true;
			digtis = size - 1;
			number *= -1;
		}
		String numStr = String.valueOf(number);
		if (digtis > numStr.length()) {
			String zero = "";
			for (int i = 0; i < digtis - numStr.length(); i++)
				zero = "0" + zero;
			numStr = zero+numStr ;
		} else if (digtis < numStr.length()) {
			numStr = numStr.substring(numStr.length() - digtis);
		}
		if (negative) {
			return "-" + numStr;
		}
		return numStr;
	}
	
	public static Object getAppMeta(String key){
		Object appMeta = null;
		try{
			Context context = AppContext.getInstance();
			ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
			if(appInfo!=null){
				appMeta = appInfo.metaData.get(key);
			}
		}catch(NameNotFoundException e){
			Logger.e("can not found the meta in the application attributes:"+key);
			
		}
		return appMeta;
	}
}
